<template>
  <div class="esgoods-container">
    <!-- 缩略图 -->
    <div class="left">
      <div class="custom-control custom-checkbox">
        <input type="checkbox" class="custom-control-input" :id="id" :checked="state" @change="onCheckboxChange">
        <label class="custom-control-label" :for="id">
          <img :src="thumb" alt="商品图片" class="thumb">
        </label>
      </div>
    </div>

    <div class="right">
      <div class="top">
        <div>{{ title }}</div>
      </div>
      <div class="bottom">
        <div class="price">&yen; {{ price.toFixed(2) }}</div>
        <div class="count">
           <es-counter :count="count" :min="1" @numchange="getnnumchange"></es-counter>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import EsCounter from '../EsCounter/EsCounter.vue'

export default {
  name: 'EsGoods',
  components:{
    EsCounter
  },
  emits: ['stateChange','countchange'],
  props: {
    id: {
      type: [String, Number],
      required: true
    },
    thumb: {
      type: String,
      required: true
    },
    title: {
      type: String,
      required: true
    },
    price: {
      type: Number,
      required: true
    },
    count: {
      type: Number,
      required: true
    },
    state: {
      type: Boolean,
      required: true
    }
  },
  methods: {
    onCheckboxChange(e) {
      this.$emit('stateChange',{ goodsId: this.id, state: e.target.checked })
    },
    getnnumchange(num){
      this.$emit('countchange',{ id: this.id, count: num})
    }
  }
}
</script>

<style lang="less" scoped>
  .esgoods-container {
    + .esgoods-container {
      border-top: 1px solid #efefef;
    }
    display: flex;
    padding: 10px;
    .left {
      margin-right: 10px;
      align-items: center;
      .thumb {
        display: block;
        width: 100px;
        height: 100px;
        background-color: #efefef;
      }
    }
    .right {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      flex: 1;
      .top {
        font-weight: 700;
      }
      .bottom {
        display: flex;
        justify-content: space-between;
        align-items: center;
        .price {
          color: red;
          font-weight: 700;
        }
      }
    }
  }

 .custom-control-label::before,
 .custom-control-label::after {
  top: 3.4rem
 }

</style>